#pragma once

#ifndef SqlSafeFilter_h__
#define SqlSafeFilter_h__

#include <QRegularExpression>
#include <QString>

namespace TCServer
{
    namespace Utility
    {
        //template <typename T>
        //struct AllowToSql
        //{
        //    enum { ALLOWED = 1};
        //};
        //
        //template <>
        //struct AllowToSql<QByteArray>
        //{
        //    enum { ALLOWED = 0 };
        //};
        //
        //template <typename T>
        //struct PreventTemplateFilterOnQString
        //{
        //    enum { IS_QSTRING = 0 };
        //};
        //template <>
        //struct PreventTemplateFilterOnQString<QString>
        //{
        //    enum { IS_QSTRING = 1 };
        //};

        class SqlFilter
        {
        public:
            static QRegularExpression stringFilter; // /\W/
            static QRegularExpression emailFilter;  // /[^a-zA-Z0-9@._]/
            static QRegularExpression phoneFilter;  // /[^0-9-]/
            //! return if there is no INVAILD characters in \a str
            static bool isValidString(const QString &str);

            //! return if there is no INVAILD characters in \a email
            static bool isValidEmail(const QString &str);

            //! return if there is no INVAILD characters in \a phone
            static bool isValidPhone(const QString &str);

            //! replace all INVAILD characters in \a str email \a replacement
            static QString filterEmail(const QString &email, const QString &replacement = "_");


            //! replace all INVAILD characters in \a phone with \a replacement
            static QString filterPhone(const QString & phone, const QString & replacement = "_");

            static QString SqlFilter::filter(QString str);

            template<class T>
            static T filter(T val)
            {
                //static_assert(AllowToSql<T>::ALLOWED, "QByteArray is not allowed to send to sql directly.");
                //static_assert(!PreventTemplateFilterOnQString<T>::IS_QSTRING, "Code design error or compiler is not supported : QString should not used by this template filter!");
                return val;
            }
        };

    }
}
#endif // SqlSafeFilter_h__
